<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>BMap 路线测试</title>
  <script src="https://api.map.baidu.com/api?v=3.0&ak=d3tbTF3DH9qSV9zWbfvjm3XMaUoYX8q7"></script>
</head>
<body>
<div id="container" style="width: 100%; height: 100vh;"></div>
<script>
  const map = new BMap.Map("container");
  map.centerAndZoom(new BMap.Point(116.680732, 39.532731), 17);

  const start = new BMap.Point(116.679635, 39.53645);
  const end = new BMap.Point(116.762638, 39.539399);

  const walking = new BMap.WalkingRoute(map, {
    onSearchComplete(result) {
      console.log('路线结果:', result);
      if (walking.getStatus() === BMAP_STATUS_SUCCESS) {
        const pts = result.getPlan(0).getRoute(0).getPath();
        const polyline = new BMap.Polyline(pts, { strokeColor: "blue", strokeWeight: 6 });
        map.addOverlay(polyline);
      }
    },
    onError(e) {
      console.error('路线规划出错:', e);
    }
  });

  map.addEventListener('tilesloaded', () => {
    console.log('地图加载完成');
    walking.search(start, end);
  });
</script>
</body>
</html>
